#include <iostream>
#include <string>
using namespace std;
//抽象工厂是应对产品族概念的。比如说，每个汽车公司可能要同时生产轿车，货车，客车，那么每一个工厂都要有创建轿车，货车和客车的方法。
//应对产品族概念而生，增加新的产品线很容易，但是无法增加新的产品

//车接口
class IVehicle
{
private:
	string type;
public:
	virtual void showType() = 0;
	IVehicle(string type)
	{
		this->type = type;
	}

	string getType()
	{
		return this->type;
	}
};

//轿车
class Car :public IVehicle
{
public:
	void showType()override
	{
		cout << this->getType() << endl;
	}
	Car(string type) :IVehicle(type)
	{

	}

};
//公交车
class Bus :public IVehicle
{
public:
	void showType()override
	{
		cout << this->getType() << endl;
	}
	Bus(string type) :IVehicle(type)
	{

	}

};

//造车的工厂(抽象工厂模式,规定只能生产Bus和Car,不能生产新的产品)
class IVehicleFactory
{
public:
	virtual Bus* createBus() = 0;
	virtual Car* createCar() = 0;
	virtual ~IVehicleFactory()
	{

	}
};

//工厂1,代表一条生产线
class VehicleFactory1 :public IVehicleFactory
{
public:
	Bus* createBus()override
	{
		return new Bus("公共汽车");
	}
	Car* createCar()override
	{
		return new Car("轿车");
	}

};
// 工厂2, 代表第二条生产线
class VehicleFactory2 :public IVehicleFactory
{
public:
	Bus* createBus()override
	{
		return new Bus("公共汽车");
	}
	Car* createCar()override
	{
		return new Car("轿车");
	}

};

void main4()
{
	IVehicleFactory * factory1 = new VehicleFactory1();
	Bus* bus = factory1->createBus();
	Car * car = factory1->createCar();
	bus->showType();
	car->showType();
	delete(bus);
	delete(car);
	delete(factory1);
	system("pause");
}